package com.zheng.upms.server.controller;

import com.zheng.common.base.BaseController;
import com.zheng.common.constant.Constant;
import com.zheng.upms.common.constant.UpmsResult;
import com.zheng.upms.common.constant.UpmsResultConstant;
import com.zheng.upms.dao.model.*;
import com.zheng.upms.rpc.api.UpmsDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 后台controller
 * Created by ZhangShuzheng on 2017/01/19.
 */
@Controller
@RequestMapping("/dict")
@Api(value = "字典数据", description = "字典数据")
public class DictController extends BaseController {

	private static final Logger LOGGER = LoggerFactory.getLogger(DictController.class);

	@Autowired
	private UpmsDictService upmsDictService;

	@ApiOperation(value = "拉取字典数据")
	@RequestMapping(value = "/loadDict", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object loadDict() {
		UpmsDictExample example = new UpmsDictExample();
		UpmsDictExample.Criteria criteria = example.createCriteria();
		criteria.andFlagEqualTo(Constant.CONST_FLAG_NORMAL);//未删除
		example.setOrderByClause(" dic_code,dic_value asc");
		List<UpmsDict> upmsDicts = upmsDictService.selectByExample(example);
		return new UpmsResult(UpmsResultConstant.SUCCESS, upmsDicts);
	}

}